home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Java Developer's Companion
/
Java Developer's Companion.iso
/
Javacup
/
IN231VFD.TAR
/
internet
/
IN231VFD
/
HouseServer.java
< prev
next >
Wrap
Text File
|
1996-05-21
|
4KB
|
137 lines
// HouseServer.java - House Server for CyberAgent
//
// Currently just returns dummied-out static data; eventually would
// contact an internet server for dynamic data.
//
// Copyright (C) 1996 by Dale Gass
// Non-exclusive license granted to MKS, Inc.
//
import java.lang.*;
import java.util.*;
import java.awt.*;
import java.net.*;
import java.applet.*;
public class HouseServer {
final static String prices[] = {
"$400,000-$999.999",
"$350,000-$399,999",
"$300,000-$349,999",
"$250,000-$299,999",
"$200,000-$249,999",
"$150,000-$199,999",
"$130,000-$149,999",
"$120,000-$129,999",
"$110,000-$119,999",
"$100,000-$109,999",
"$ 90,000-$ 99,999",
"$ 80,000-$ 89,999",
"$ 70,000-$ 79,999",
"$ 60,000-$ 69,999",
"$ 50,000-$ 59,999",
"Under $50,000"
};
final static int pricelow[] = {
400000, 350000, 300000, 250000, 200000, 150000, 130000, 120000,
110000, 100000, 90000, 80000, 70000, 60000, 50000, 0
};
final static int pricehigh[] = {
999999, 399999, 349999, 299999, 249999, 199999, 149999, 129999,
119999, 109999, 99999, 89999, 79999, 69999, 59999, 49999
};
final static String beds[] = {
"5+", "4", "3", "2", "1"
};
final static String areas[] = {
"Halifax", "Bedford", "Dartmouth", "County"
};
House[] listings;
// Constructor - build the standard listings
public HouseServer() {
listings = new House[3];
listings[0]=new House("Townhouse", "Bedford", 120000,5,true, "aaa");
listings[1]=new House("House", "Halifax", 200000,2,false, "aab");
listings[2]=new House("Shack", "Dartmouth", 80000,3,false, "aac");
}
// Enumerate each of the criteria
public String[] enumPrices() { return prices; }
public String[] enumBeds() { return beds; }
public String[] enumAreas() { return areas; }
int getIndex(int array[], int val) {
int i;
for (i=0; i<array.length; i++)
if (array[i] == val)
break;
if (i == array.length)
i = -1;
return i;
}
// Perform a server query
public Vector query(int priceA[], int areaA[], int bedA[]) {
Vector result = new Vector();
int i;
for (i=0; i<listings.length; i++) {
House h = listings[i];
String a = h.getArea();
int areacode;
for (areacode=0; areacode<areas.length; areacode++)
if (a.equals(areas[areacode]))
break;
int range, p = h.getPrice();
for (range=0; range<prices.length; range++) {
if (p>= pricelow[range] && p <= pricehigh[range])
break;
}
int b = h.getBeds(); /* Convert bed count to beds[] index */
if (b > 5)
b = 0;
else
b = 5 - b;
/* We now have price "range", "areacode", and number of beds
* to match against our search criteria
*/
if (getIndex(areaA, areacode) != -1 &&
getIndex(priceA,range ) != -1 &&
getIndex(bedA, b ) != -1)
result.addElement(h);
}
return (result);
}
// Get the camera views for given house and floor (0 == basement)
public static Camera []getCameras(House h, int floor) {
Camera cams[];
if (floor == 0) {
cams = new Camera[2];
cams[0] = new Camera(320, 220, 100, "Office");
cams[1] = new Camera(345, 150, 80, "Family Room");
} else if (floor == 1) {
cams = new Camera[3];
cams[0] = new Camera(355, 145, 135, "Kitchen");
cams[1] = new Camera(105, 85, 60, "Living Room");
cams[2] = new Camera(290, 190, 270, "Entrance");
} else {
cams = new Camera[3];
cams[0] = new Camera(355, 135, 80, "Bedroom");
cams[1] = new Camera(380, 245, 90, "Bathtub");
cams[2] = new Camera(505, 165, 200, "Bathroom");
}
return (cams);
};
}